%
% Used for resource http://matlabgeeks.com/tips-tutorials/how-to-do-a-fourier-transform-in-matlab/
% Charles Cloud
% Team: Come back zach!
%
% Returns the fundamental frequency of an array of samples
%

function [fundFreq]= fundFreqSamples(samples, ampThreshold, Fs)

%length of the array
numSamples = length(samples);

%fourier transform
y_fft = abs(fft(samples));          


%we need an amplitude threshhold to look at
%use input for now. Look at an average later?

%now we find the fundamental frequency. 
%it is the lowest significant signal in our array
for i=1:numSamples
    if(y_fft(i) >= ampThreshold)
        %the fraction of the amount we are into the frequency spectrum
        %multiplied by the sampling rate that we used
        fundFreqCalc = Fs*(i/numSamples);
        break;
    end
end

fundFreq = fundFreqCalc;
    